__author__ = 'aesop'
#coding:utf-8

import models.group as group_operate
import models.stuinfo as stu_info

def gen_group(group_member_func,arg, name):
    return group_operate.new_group( {
        "group_member":group_member_func(arg),
        "owner":'0',
        "group_name":name
    });

#用于转换的字典
#@TODO
class2name_dic = {
    "121279":u"12金工",
    "121270":u"12自动",
    "121271":u"12信工",
    "121278":u"12工工",
    "131270":u"13电气",
    "131279":u"13管科",
    "141270":u"14电气",
    "141279":u"14管科",
    "111111":u"其他",
    "121275":u"12班委"
}


#增加所有学生分组
def all_stu(a = 1):
    return [ {'stu_id':item[0], 'name':item[1]} for item in stu_info.find_all_stu()]

def grade_stu(grade):
    return [ {'stu_id':item[0], 'name':item[1]}  for item in stu_info.find_stu_by_grade(grade) ]

def class_stu(class_number):
    return [ {'stu_id':item[0], 'name':item[1]}  for item in stu_info.find_stu_by_class(class_number) ]


gen_group(all_stu,None,u"全部")

grade_list = [12,13,14]
map(lambda x: gen_group(grade_stu,x,str(x)+u"级"), grade_list)

class_stu_list = ["121279", "121270","121271","121278","131270","131279",
                  "141270", "141279","111111","121275"]
map(lambda x: gen_group(class_stu, x, class2name_dic[x]), class_stu_list)

